﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace WPFExcelReport
{
    /*
       * Public Method CloseComm 关闭comm 端口 
       * Public Method ExecuteCommand 执行命令 
       * Public Method GetDataPart 获取指定数据部分 
       * Public Method OpenComm 打开com 口 
       */
  
    public struct COPYDATASTRUCT
    {
        public IntPtr dwData;
        public IntPtr cbData;
        public IntPtr lpData;
        //public int cbData;
        //[MarshalAs(UnmanagedType.LPStr)]
        //public string lpData; 
    }
    /*  public struct COPYDATASTRUCT
    {
        public int dwData;
        public int cbData;
        [MarshalAs(UnmanagedType.LPStr)]
        public string lpData;
    }*/

    public class MabuCommAPI
    {
        public const int WM_COPYDATA = 0x004A;
        [DllImport("User32.dll")]
        public static extern int SendMessage(long hwnd, int msg, int wParam, ref COPYDATASTRUCT lParam);

        /*
        [DllImport("User32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("User32.dll")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("User32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr SendMessage(long hwnd, int wMsg, IntPtr wParam, ref COPYDATASTRUCT lParam);

        [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
        public static extern void CopyMemory(IntPtr pDst, String pSrc, System.Int32 ByteLen);

        [DllImport("MabuComm.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern void comm();
        [DllImport("MabuComm.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void CloseComm();
        [DllImport("MabuComm.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void ExecuteCommand();
        [DllImport("MabuComm.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void GetDataPart();
        [DllImport("MabuComm.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void OpenComm();
        [DllImport("MabuComm.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void ReadCounterSpeed();*/


    }
}
